﻿#pragma strict

var speed : float;
var destination : Vector3;
var source : Vector3;
var left : Vector3;
var right : Vector3;
var startTime : float;
var offset : float;

function Start () {
	startTime = Time.time;
	source = transform.position;
	destination = transform.position;
	destination.x = transform.position.x - (right.x-left.x);
	speed = .05;	
}

function Update () {
	transform.position = Vector3.Lerp(source,destination,(Time.time - startTime)*speed);
	if(transform.position.x <= left.x) {
		source = right;
		destination = left;
		transform.position = source;
		startTime = Time.time;
	}
}